Skip to content

Conversation

@netmindz
Copy link
Collaborator

@netmindz netmindz commented Jan 31, 2026

Summary by CodeRabbit

  • Refactor

    • Updated Audioreactive integration: expanded build flags and library declarations and added an automated pre-build patch step.
    • Removed several audio input source implementations and their public interfaces, affecting supported microphones.
    • Adjusted usermod include resolution.
  • Documentation

    • Removed Audioreactive usermod documentation.
  • Bug Fix / Internal

    • Relocated internal numeric mapping utility (prevents duplicate symbol issues).

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Jan 31, 2026

📝 Walkthrough

Walkthrough

Adds a pre-build script that patches the wled-audioreactive library.json to exclude C++ sources; updates platformio.ini to pull Audioreactive and arduinoFFT from external repos and propagate build flags; removes local audioreactive header and README; switches the usermod include to the external header.

Changes

Cohort / File(s) Summary
Build & patch infra
pio-scripts/patch_audioreactive.py, platformio.ini
Add patch_audioreactive.py and register it as a pre-build script; add multi-line AR_build_flags and split AR_lib_deps into two external repos (WLED-AudioReactive-Usermod#compat-MM, arduinoFFT@1.9.2); propagate flags/deps into multiple environments.
Removed local audioreactive implementation
usermods/audioreactive/audio_source.h, usermods/audioreactive/readme.md
Delete local audio_source.h (removes AudioSource and all concrete I2S/ADC drivers/interfaces) and remove the Audioreactive README documentation.
Integration include update
wled00/usermods_list.cpp
Change AUDIOREACTIVE include from a relative path to a system-style include to reference the external usermod header.
Utility function adjustment
wled00/FX.cpp, wled00/fcn_declare.h
Remove mapf implementation from FX.cpp and add a static mapf(...) utility in fcn_declare.h.

Sequence Diagram(s)

sequenceDiagram
  participant P as PlatformIO
  participant S as patch_audioreactive.py
  participant FS as Filesystem
  participant L as wled-audioreactive library
  participant B as Build

  P->>S: run pre-build script
  S->>FS: locate `PROJECT_LIBDEPS_DIR/$PIOENV/wled-audioreactive/library.json`
  alt file exists & readable
    S->>L: read `library.json`
    S->>S: ensure `build.srcFilter` exists and set to ["-<*>"]
    S->>L: write updated `library.json`
    S-->>P: print success
  else missing or error
    S-->>P: print warning / no-op
  end
  P->>B: continue build (uses updated deps/includes)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I hopped through code and left a stitch,
Tucked audio bits into an external niche,
A tiny script closed C++ doors,
Flags and deps now cross the moors,
I nibble bugs and sniff the switch.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change—moving AudioReactive functionality from internal source to an external repository.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@pio-scripts/patch_audioreactive.py`:
- Around line 21-31: The code currently only sets
library_config["build"]["srcFilter"] when the key is missing; instead, check the
existing value and enforce ["-<*>"] whenever it differs: ensure library_config
has a "build" dict (create if missing), read current =
library_config["build"].get("srcFilter"), and if current != ["-<*>"] then set
library_config["build"]["srcFilter"] = ["-<*>"], write back to library_json_path
with json.dump, and print the success message; reference the symbols
library_config, "build", "srcFilter", and library_json_path to locate the
change.

Comment on lines +21 to +31
# Add srcFilter to exclude all source files from library compilation
if "build" not in library_config:
library_config["build"] = {}

if "srcFilter" not in library_config["build"]:
library_config["build"]["srcFilter"] = ["-<*>"]

with open(library_json_path, 'w') as f:
json.dump(library_config, f, indent=2)

print("✓ Patched wled-audioreactive library.json to exclude .cpp from compilation")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

cat -n pio-scripts/patch_audioreactive.py | head -40

Repository: MoonModules/WLED-MM

Length of output: 1866


Enforce srcFilter even when it already exists

The patch only applies when srcFilter is missing. If the upstream library is updated with a different srcFilter value that still includes sources, the patch won't override it and builds will unintentionally compile those .cpp files. Update the logic to compare the current value with the desired one and enforce ["-<*>"] whenever it differs.

🛠️ Suggested fix
-            # Add srcFilter to exclude all source files from library compilation
-            if "build" not in library_config:
-                library_config["build"] = {}
-            
-            if "srcFilter" not in library_config["build"]:
-                library_config["build"]["srcFilter"] = ["-<*>"]
-                
-                with open(library_json_path, 'w') as f:
-                    json.dump(library_config, f, indent=2)
-                
-                print("✓ Patched wled-audioreactive library.json to exclude .cpp from compilation")
+            # Add srcFilter to exclude all source files from library compilation
+            build_cfg = library_config.get("build")
+            if not isinstance(build_cfg, dict):
+                build_cfg = {}
+                library_config["build"] = build_cfg
+
+            desired_filter = ["-<*>"]
+            if build_cfg.get("srcFilter") != desired_filter:
+                build_cfg["srcFilter"] = desired_filter
+
+                with open(library_json_path, 'w') as f:
+                    json.dump(library_config, f, indent=2)
+
+                print("✓ Patched wled-audioreactive library.json to exclude .cpp from compilation")
🤖 Prompt for AI Agents
In `@pio-scripts/patch_audioreactive.py` around lines 21 - 31, The code currently
only sets library_config["build"]["srcFilter"] when the key is missing; instead,
check the existing value and enforce ["-<*>"] whenever it differs: ensure
library_config has a "build" dict (create if missing), read current =
library_config["build"].get("srcFilter"), and if current != ["-<*>"] then set
library_config["build"]["srcFilter"] = ["-<*>"], write back to library_json_path
with json.dump, and print the success message; reference the symbols
library_config, "build", "srcFilter", and library_json_path to locate the
change.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
platformio.ini (1)

197-197: ⚠️ Potential issue | 🟠 Major

Fix invalid PlatformIO dependency specification syntax.

The specification https://github.com/softhack007/arduinoFFT.git#develop @ 1.9.2 violates PlatformIO format. You cannot mix # (VCS reference) and @ (Registry version) together. PlatformIO uses @ only for registry packages and # only for git references—never both.

For a Git URL, use one of:

  • https://github.com/softhack007/arduinoFFT.git#develop (pin to develop branch)
  • https://github.com/softhack007/arduinoFFT.git#v1.9.2 (pin to version tag if it exists)
🤖 Fix all issues with AI agents
In `@platformio.ini`:
- Line 231: The pre-build script pre:pio-scripts/patch_audioreactive.py
currently swallows failures and merely prints a warning; change it to verify the
patch succeeded and fail the build on error by either (a) validating that
library.json contains the expected modifications after applying the patch (e.g.,
checking for the expected key/value or version) and exiting non-zero when
validation fails, or (b) rethrowing the caught exception / calling sys.exit(1)
from the main entry point instead of only logging a warning so the PlatformIO
build is aborted; update the script’s exception handlers to perform this
verification and ensure any file-not-found, JSON parse, or write errors become
fatal.

pre:pio-scripts/build_ui.py
pre:pio-scripts/conditional_usb_mode.py
pre:pio-scripts/set_repo.py
pre:pio-scripts/patch_audioreactive.py
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

# Search for the patch script and verify its existence
find . -name "patch_audioreactive.py" -o -name "*patch*" -type f | head -20

Repository: MoonModules/WLED-MM

Length of output: 99


🏁 Script executed:

# Check the pio-scripts directory structure
ls -la pio-scripts/ 2>/dev/null || echo "pio-scripts directory check"
git ls-files | grep -E "pio-scripts|patch" | head -20

Repository: MoonModules/WLED-MM

Length of output: 1426


🏁 Script executed:

# Examine the platformio.ini file around line 231 to see the context
sed -n '225,235p' platformio.ini

Repository: MoonModules/WLED-MM

Length of output: 524


🏁 Script executed:

cat pio-scripts/patch_audioreactive.py

Repository: MoonModules/WLED-MM

Length of output: 1607


Script exists and has error handling, but failures are non-critical.

The patch_audioreactive.py script is properly registered and implemented with exception handling. However, the error handling is permissive—if the patch fails, the script only prints a warning and allows the build to continue. This means if the library.json patch is not applied due to an error (file not found, JSON parse failure, etc.), the build will proceed unpatched, potentially causing compilation errors downstream that are harder to trace back to the patch failure.

Consider adding explicit verification that the patch was successfully applied, or make patch failures fatal to the build if the patched library is required for compilation.

🤖 Prompt for AI Agents
In `@platformio.ini` at line 231, The pre-build script
pre:pio-scripts/patch_audioreactive.py currently swallows failures and merely
prints a warning; change it to verify the patch succeeded and fail the build on
error by either (a) validating that library.json contains the expected
modifications after applying the patch (e.g., checking for the expected
key/value or version) and exiting non-zero when validation fails, or (b)
rethrowing the caught exception / calling sys.exit(1) from the main entry point
instead of only logging a warning so the PlatformIO build is aborted; update the
script’s exception handlers to perform this verification and ensure any
file-not-found, JSON parse, or write errors become fatal.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Fix all issues with AI agents
In `@platformio.ini`:
- Around line 1189-1198: The AR_lib_deps entry for arduinoFFT is an invalid
mixed-format spec; update the AR_lib_deps line referencing arduinoFFT (currently
"https://github.com/softhack007/arduinoFFT.git#develop @ 1.9.2") to a valid
VCS-only spec by removing the "@ 1.9.2" suffix (or alternatively pin a specific
git tag/commit after the "#" instead of using "@version"); ensure AR_lib_deps
contains a clean VCS URL for arduinoFFT so PlatformIO can resolve it.
- Around line 1612-1614: The esp8266 AR-enabled env is pulling
${common_mm.AR_lib_deps} but missing the matching build flags; update the
esp8266_2MB_S environment so its build_flags include ${common_mm.AR_build_flags}
(in the same place where build_flags = ${common.build_flags_esp8266} is
declared) so the -D USERMOD_AUDIOREACTIVE define and include paths from
common_mm.AR_build_flags are applied; ensure the change mirrors how
esp8266pro_16MB_S and ESP32 AR environments include both
${common_mm.AR_lib_deps} and ${common_mm.AR_build_flags}.

Comment on lines 1189 to 1198
AR_build_flags =
-D USERMOD_AUDIOREACTIVE
-D UM_AUDIOREACTIVE_USE_NEW_FFT
-I wled00 ;; Allow external AudioReactive library to access wled.h
-I $PROJECT_LIBDEPS_DIR/$PIOENV/wled-audioreactive ;; Allow main project to find audio_reactive.h
;; WLEDMM audioreactive usermod, licensed under EUPL-1.2
;; NOTE: External repo needs library.json updated with "srcFilter": ["-<*>"] to prevent .cpp compilation
AR_lib_deps =
https://github.com/MoonModules/WLED-AudioReactive-Usermod.git#39fee0aebc4f7581f23723acc710ea9cacc199d1 ;; MM version 14
https://github.com/softhack007/arduinoFFT.git#develop @ 1.9.2 ;; used for USERMOD_AUDIOREACTIVE - optimized version, 10% faster on -S2/-C3
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🌐 Web query:

PlatformIO library dependency specification syntax VCS git branch version

💡 Result:

In platformio.ini, lib_deps entries use Package Specifications. There are two common cases:

1) PlatformIO Registry libraries (SemVer / version requirements)

Syntax:

  • <owner>/<name>@<version requirement>

Examples:

2) VCS (Git) dependencies (pin branch/tag/commit with #)

Syntax:

  • [<name>=]<git-url>[#<commit-ish|branch|tag>]

Examples:

Key distinction: @ vs #

  • Use @... for Registry version constraints.
  • Use #... for Git branch/tag/commit when the dependency is a VCS URL. (docs.platformio.org)

Citations:


🌐 Web query:

PlatformIO lib_deps format mixed version specifier git reference

💡 Result:

In lib_deps, you can’t combine the registry SemVer specifier syntax (owner/name @ ^1.2.3, ~, !=, etc.) with a VCS (git) reference (...git#branch|tag|commit) in the same dependency entry—they are two different kinds of package specifications:

  • PlatformIO Registry library + SemVer constraints uses @:
  • Git (or other VCS) dependency uses a URL (or user/repo) plus # for branch/tag/commit:

If you want “versioning” with git

You must do it by pinning to a tag (e.g., #v1.2.3) or a commit SHA—there’s no SemVer range resolution for arbitrary git URLs in lib_deps like #^1.2.3. (docs.platformio.org)

Citations:


Fix invalid PlatformIO lib spec for arduinoFFT.
https://github.com/softhack007/arduinoFFT.git#develop @ 1.9.2 mixes VCS syntax (#branch) with registry versioning (@version). PlatformIO does not support combining both formats in a single dependency entry. Remove the @ 1.9.2 portion to use the valid VCS-only specification.

🛠️ Suggested fix
 AR_lib_deps =
   https://github.com/MoonModules/WLED-AudioReactive-Usermod.git#39fee0aebc4f7581f23723acc710ea9cacc199d1 ;; MM version 14
-  https://github.com/softhack007/arduinoFFT.git#develop @ 1.9.2      ;; used for USERMOD_AUDIOREACTIVE - optimized version, 10% faster on -S2/-C3
+  https://github.com/softhack007/arduinoFFT.git#develop              ;; used for USERMOD_AUDIOREACTIVE - optimized version, 10% faster on -S2/-C3
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
AR_build_flags =
-D USERMOD_AUDIOREACTIVE
-D UM_AUDIOREACTIVE_USE_NEW_FFT
-I wled00 ;; Allow external AudioReactive library to access wled.h
-I $PROJECT_LIBDEPS_DIR/$PIOENV/wled-audioreactive ;; Allow main project to find audio_reactive.h
;; WLEDMM audioreactive usermod, licensed under EUPL-1.2
;; NOTE: External repo needs library.json updated with "srcFilter": ["-<*>"] to prevent .cpp compilation
AR_lib_deps =
https://github.com/MoonModules/WLED-AudioReactive-Usermod.git#39fee0aebc4f7581f23723acc710ea9cacc199d1 ;; MM version 14
https://github.com/softhack007/arduinoFFT.git#develop @ 1.9.2 ;; used for USERMOD_AUDIOREACTIVE - optimized version, 10% faster on -S2/-C3
AR_build_flags =
-D USERMOD_AUDIOREACTIVE
-D UM_AUDIOREACTIVE_USE_NEW_FFT
-I wled00 ;; Allow external AudioReactive library to access wled.h
-I $PROJECT_LIBDEPS_DIR/$PIOENV/wled-audioreactive ;; Allow main project to find audio_reactive.h
;; WLEDMM audioreactive usermod, licensed under EUPL-1.2
;; NOTE: External repo needs library.json updated with "srcFilter": ["-<*>"] to prevent .cpp compilation
AR_lib_deps =
https://github.com/MoonModules/WLED-AudioReactive-Usermod.git#39fee0aebc4f7581f23723acc710ea9cacc199d1 ;; MM version 14
https://github.com/softhack007/arduinoFFT.git#develop ;; used for USERMOD_AUDIOREACTIVE - optimized version, 10% faster on -S2/-C3
🤖 Prompt for AI Agents
In `@platformio.ini` around lines 1189 - 1198, The AR_lib_deps entry for
arduinoFFT is an invalid mixed-format spec; update the AR_lib_deps line
referencing arduinoFFT (currently
"https://github.com/softhack007/arduinoFFT.git#develop @ 1.9.2") to a valid
VCS-only spec by removing the "@ 1.9.2" suffix (or alternatively pin a specific
git tag/commit after the "#" instead of using "@version"); ensure AR_lib_deps
contains a clean VCS URL for arduinoFFT so PlatformIO can resolve it.

Comment on lines +1612 to 1614
lib_deps = ${esp8266.lib_deps}
${common_mm.AR_lib_deps}
build_flags = ${common.build_flags_esp8266}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

# First, let's locate and examine the esp8266_2MB_S environment section
rg -n "esp8266_2MB_S" platformio.ini -A 10 -B 2

Repository: MoonModules/WLED-MM

Length of output: 1430


🏁 Script executed:

# Find where common_mm.AR_lib_deps and common_mm.AR_build_flags are defined
rg -n "AR_lib_deps|AR_build_flags" platformio.ini -B 2 -A 2

Repository: MoonModules/WLED-MM

Length of output: 5568


🏁 Script executed:

# Check the structure of the file to understand the context better
wc -l platformio.ini

Repository: MoonModules/WLED-MM

Length of output: 82


🏁 Script executed:

# Check for comments around the 2MB, 4MB, and 16MB environments
sed -n '1608,1625p' platformio.ini
sed -n '1638,1650p' platformio.ini
sed -n '1736,1745p' platformio.ini

Repository: MoonModules/WLED-MM

Length of output: 1839


🏁 Script executed:

# Verify that common_mm.AR_build_flags is properly defined
sed -n '1189,1200p' platformio.ini

Repository: MoonModules/WLED-MM

Length of output: 872


Add AR_build_flags to esp8266_2MB_S build configuration.

The environment pulls ${common_mm.AR_lib_deps} but omits ${common_mm.AR_build_flags}, which includes the -D USERMOD_AUDIOREACTIVE define and required include paths. Without these flags, the AudioReactive library will fail to compile. This is inconsistent with esp8266pro_16MB_S and all ESP32 AR-enabled environments, which include both.

✅ Suggested fix:
 build_flags = ${common.build_flags_esp8266}
+  ${common_mm.AR_build_flags}
   -D WLED_RELEASE_NAME=esp8266_2MB_S
🤖 Prompt for AI Agents
In `@platformio.ini` around lines 1612 - 1614, The esp8266 AR-enabled env is
pulling ${common_mm.AR_lib_deps} but missing the matching build flags; update
the esp8266_2MB_S environment so its build_flags include
${common_mm.AR_build_flags} (in the same place where build_flags =
${common.build_flags_esp8266} is declared) so the -D USERMOD_AUDIOREACTIVE
define and include paths from common_mm.AR_build_flags are applied; ensure the
change mirrors how esp8266pro_16MB_S and ESP32 AR environments include both
${common_mm.AR_lib_deps} and ${common_mm.AR_build_flags}.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
platformio.ini (1)

1636-1642: ⚠️ Potential issue | 🟡 Minor

Add AR_build_flags to esp8266_4MB_S build configuration.

The environment pulls ${common_mm.AR_lib_deps} (lines 1640-1641) but omits ${common_mm.AR_build_flags} from build_flags (line 1642). This mirrors the issue in esp8266_2MB_S and contrasts with esp8266pro_16MB_S (line 1741), which correctly includes both. Without these flags, the AudioReactive library will fail to compile due to missing defines and include paths.

✅ Suggested fix:
 build_flags = ${common.build_flags_esp8266}
+  ${common_mm.AR_build_flags}
   -D WLED_RELEASE_NAME=esp8266_4MB_S

;; WLEDMM audioreactive usermod, licensed under EUPL-1.2
;; NOTE: External repo needs library.json updated with "srcFilter": ["-<*>"] to prevent .cpp compilation
AR_lib_deps =
https://github.com/netmindz/WLED-AudioReactive-Usermod.git#compat-MM ;; MM version 14
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be swapped to MoonModules once we are good to merge the compat-MM PR

@netmindz
Copy link
Collaborator Author

I've just done a basic test and usermod can be enabled and the settings all look as I would expect

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant